package com.xuecheng.learning.controller;

import com.xuecheng.commons.model.dto.RecordDto;
import com.xuecheng.commons.model.vo.LearningProgressDto;
import com.xuecheng.commons.model.vo.ResourceVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 选课记录前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping
public class CourseRecordController {

    @Autowired
    private CourseRecordService  courseRecordService;

    /**
     * 获取当前课程发布的学习进度
     */
    @GetMapping("learnedRecords/myCourseRec/{coursePubId}")
    public ResponseResult myCourseRec (@PathVariable("coursePubId") Long coursePubId) {
        return courseRecordService.findByCoursePubId(coursePubId);
    }

    //获取课程视频资源地址
    @GetMapping("learnedRecords/resource-url")
    public ResponseResult<ResourceVo> findPlayUrl (Long coursePubId,Long mediaId,Long teachplanId) {
        return courseRecordService.findPlayUrl(coursePubId,mediaId,teachplanId);
    }

    //保存或者更新学习记录
    @PostMapping("learnedRecords/progress")
    public ResponseResult progress (@RequestBody LearningProgressDto dto) {
        return courseRecordService.progress(dto);
    }
}
